package org.zk.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zk.dao.UserDao;
import org.zk.entity.User;

import java.util.List;
import java.util.Map;

@Service
public class UserService {

    @Autowired
    private UserDao userDao;


    public Page queryLikeUsers(Map<String, Object> cond) {
        Page page = new Page();
        //总条数
        page.setTotal(userDao.getLikeUsersCount(cond));
        //分别获取当前页和每页条数
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);

        int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(curPageNum);

        page = PageHelper.startPage(curPageNum, pageSize);
        try {
            List list = userDao.getLikeUsers(cond);
        }catch (Exception e){
            e.printStackTrace();
        }


        return page;
    }


    public User getUserById(int userid) {
        return userDao.getUserById(userid);
    }

    public int updateUser(User user) {
        return userDao.editUser(user);
    }


    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
